const userService = require('../services/users')
const _ = require('../node_modules/lodash')
const moment = require('../node_modules/moment')
const { result } = require('lodash')

async function login(ctx,next){

    await ctx.render('login')
}
async function setCookie(ctx,next){
    let { content } = ctx.request.query
    if(ctx.cookies.set('user',JSON.stringify({content}))){
        data.status = 'success'
      }
      ctx.response.body = data
}
async function sendMassage(ctx,next){
    let { content } = ctx.request.query
    let { content } = JSON.parse(ctx.cookies.get('user'))
    await userService({content})
    ctx.response.body = {status:'success',content}
}
async function getContent(ctx){
    
    let times = {
      $gte:moment().subtract(1,'day').toDate(),
      $lte:moment().toDate()
    }
    let contents = await userService.timeContent(times) 
    ctx.response.body=contents
  }
module.exports = {
    login,
    sendMassage,
    setCookie,
    getContent
}
